package cur.nature.admin.dao;

import cur.nature.admin.common.config.DBAdminConfig;
import cur.nature.admin.model.po.Admin_Mid_RoleResourcePO;
import cur.nature.admin.model.po.Admin_Mid_UserDeptPO;
import cur.nature.admin.model.po.Admin_Mid_UserRolePO;
import cur.nature.framework.core.util.StringUtil;
import cur.nature.tinyorm.core.proxy.TemplateProxy;
import cur.nature.tinyorm.core.template.DefaultJdbcTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 用户信息 Dao
 * 作者：Auto Generator By wujian
 * 生成日期：2023-07-10 21:42:14
 */
@Component
@DependsOn(DefaultJdbcTemplate.TEMPLATE)
public class Admin_MidDao {

    private DefaultJdbcTemplate template;
    private TemplateProxy templateProxy;

    public Admin_MidDao(@Qualifier(DBAdminConfig.TEMPLATE) DefaultJdbcTemplate template) {
        this.template = template;
        this.templateProxy = template.getTemplateProxy();
    }

    public List<Admin_Mid_UserRolePO> queryUserRole(List<Long> userIdList) throws Exception {
        List<Admin_Mid_UserRolePO> list = templateProxy.queryByCond(
                "and user_id in (" + StringUtil.convertArrayToStr(userIdList) + ")",
                Admin_Mid_UserRolePO.class);
        return list;
    }

    public int deleteUserRoleByUserId(Long userId) throws Exception {
        return templateProxy.deleteByCond("and user_id=" + userId + "",
                Admin_Mid_UserRolePO.class);
    }

    public List<Admin_Mid_UserDeptPO> queryUserDept(List<Long> userIdList) throws Exception {
        List<Admin_Mid_UserDeptPO> list = templateProxy.queryByCond(
                "and user_id in (" + StringUtil.convertArrayToStr(userIdList) + ")",
                Admin_Mid_UserDeptPO.class);
        return list;
    }

    public int deleteUserDeptByUserId(Long userId) throws Exception {
        return templateProxy.deleteByCond("and user_id=" + userId + "",
                Admin_Mid_UserDeptPO.class);
    }

    public List<Admin_Mid_RoleResourcePO> queryRoleResource(List<String> roleIdList) throws Exception {
        List<Admin_Mid_RoleResourcePO> list = templateProxy.queryByCond(
                "and role_id in (" + StringUtil.convertArrayToStr(roleIdList) + ")",
                Admin_Mid_RoleResourcePO.class);
        return list;
    }

    public int deletRoleResourceByRoleId(Long roleId) throws Exception {
        return templateProxy.deleteByCond("and role_id=" + roleId + "",
                Admin_Mid_RoleResourcePO.class);
    }
}

